package com.jstyle.jclifexd.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.jstyle.jclifexd.R;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2018/6/11.
 */

public class WatchFaceStyleCustomAdapter extends RecyclerViewBaseAdapter {


    public WatchFaceStyleCustomAdapter(Object o) {
        super(o);
    }

    int selectedPosition = -1;

    @Override
    protected void bindData(BaseViewHolder holder, final int position) {
        WatchDaceStyleViewHolder watchDaceStyleViewHolder = (WatchDaceStyleViewHolder) holder;
        Context context = holder.itemView.getContext();
        watchDaceStyleViewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                selectedPosition = position;
                notifyDataSetChanged();
                if (listener != null) listener.onItemClick(position);
            }
        });
        // watchDaceStyleViewHolder.ImageViewStyle.setImageResource();

        watchDaceStyleViewHolder.ImageViewStyleSelected.setVisibility(position == selectedPosition ? View.VISIBLE : View.INVISIBLE);

        int id = context.getResources().getIdentifier(position==0?"watch_custom_" + position:"style_"+position, "drawable", context.getPackageName());
        watchDaceStyleViewHolder.ImageViewStyle.setImageResource(id);
    }
    public int getSelectedPosition(){
        return  selectedPosition;
    }
    public void setSelectedPosition(int position){
        if(position<64)return;
        this.selectedPosition=position-64;
        notifyDataSetChanged();
    }
    @Override
    protected int getLayoutId(int viewType) {

        return R.layout.item_watchface_style;
    }


    @Override
    public BaseViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        BaseViewHolder baseViewHolder = null;

        View viewOther = LayoutInflater.from(parent.getContext()).inflate(getLayoutId(viewType), parent, false);
        baseViewHolder = new WatchDaceStyleViewHolder(viewOther);

        return baseViewHolder;
    }

    public class WatchDaceStyleViewHolder extends BaseViewHolder {

        @BindView(R.id.ImageView_style)
        ImageView ImageViewStyle;
        @BindView(R.id.iv_style_selected)
        ImageView ImageViewStyleSelected;

        public WatchDaceStyleViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

    @Override
    public int getItemCount() {
        return 7;
    }

    onItemClickListener listener;

    public void setOnContactClickListener(onItemClickListener onItemClickListener) {
        this.listener = onItemClickListener;
    }

    public interface onItemClickListener {
        public void onItemClick(int position);
    }

}
